package cn.poletech.cat.tx.core.util.config;


import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;

/**
 * @author magic.s.g.xie
 * @date 2021年06月01日 11:03
 */
public class ConfigHelper {
    private String propertyPath;
    private Props propertiesConfiguration = null;

    public String getStringValue(String key) {
        return propertiesConfiguration.getStr(key);
    }

    public String[] getStringArrayValue(String key) {
        return StrUtil.split(propertiesConfiguration.getStr(key),StrUtil.COMMA);
    }

    public void setProperty(String key, Object val) {
        propertiesConfiguration.setProperty(key, val);
        propertiesConfiguration.store(propertyPath);
    }

    public int getIntValue(String key) {
        return propertiesConfiguration.getInt(key);
    }

    public float getFloatValue(String key) {
        return propertiesConfiguration.getFloat(key);
    }

    public ConfigHelper(String propertyPath) {
        this.propertyPath = propertyPath;
        try {
            propertiesConfiguration = new Props(propertyPath);
        } catch (Exception e) {
            throw new RuntimeException(
                    "Please configure check  file: " + propertyPath);
        }
    }

}
